package org.txazo.blog.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.txazo.blog.dao.MemberInfoDao;
import org.txazo.blog.service.MemberInfoService;
import org.txazo.blog.vo.MemberInfo;

import com.googlecode.ehcache.annotations.Cacheable;
import com.googlecode.ehcache.annotations.TriggersRemove;

/**
 * 用户信息模块业务逻辑实现
 * 
 * @author Tu XiaoZhou
 * @since 2013-08-10
 */
@Transactional
@Service("memberInfoService")
public class MemberInfoServiceImpl implements MemberInfoService {

	@Autowired
	private MemberInfoDao memberInfoDao;

	@Override
	public boolean isEmailAccountExist(String emailAccount) {
		return memberInfoDao.isEmailAccountExist(emailAccount);
	}

	@Override
	@TriggersRemove(cacheName = "org.txazo.cache.MemberInfoCache", removeAll = true)
	public int addMemberInfo(MemberInfo memberInfo) {
		boolean result = memberInfoDao.addMemberInfo(memberInfo);
		if (result) {
			return memberInfoDao.getMemberId(memberInfo.getEmailAccount());
		}
		return -1;
	}

	@Override
	@TriggersRemove(cacheName = "org.txazo.cache.MemberInfoCache", removeAll = true)
	public boolean updateMemberInfo(MemberInfo memberInfo) {
		return memberInfoDao.updateMemberInfo(memberInfo);
	}

	@Override
	@Cacheable(cacheName = "org.txazo.cache.MemberInfoCache")
	public MemberInfo getMemberInfo(String emailAccount) {
		return memberInfoDao.getMemberInfo(emailAccount);
	}

}
